<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/style.css">
    <script>
    if (top != self) { top.location.href = location.href; }
    </script>
</head>
<body>
    <div class="header layui-clear">
        <div class="logo">
            <img src="/static/images/logo.png" alt="">
        </div>
        <div class="menu">
            <ul class="layui-nav">
                <li class="layui-nav-item layui-this">
                    <a href="{:url('admin/index/main')}" target="iframe"><i class="layui-icon layui-icon-home"></i> 管理首页</a>
                </li>
                {foreach $menu as $k => $v}
                <li class="layui-nav-item">
                    <a href="{:is_string($v)?:'javascript:;'}">{$k}</a>
                    {if is_array($v)}
                    <dl class="layui-nav-child">
                        {foreach $v as $kk => $vv}
                        <dd><a href="{:url('admin/'.$vv.'/'.$vv)}" target="iframe">{$kk}</a></dd>
                        {/foreach}
                    </dl>
                    {/if}
                </li>
                {/foreach}
            </ul>
        </div>
        <div class="other">
            <ul class="layui-nav">
                <li class="layui-nav-item">
                    <a href="/" target="_blank"><i class="layui-icon layui-icon-eye"></i> 预览网站</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-username"></i> {:session('user.name')}</a>
                    <dl class="layui-nav-child">
                        <dd><a id="setPassword" href="javascript:;">修改密码</a></dd>
                        <dd><a id="logout" href="javascript:;">退出登录</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="pos layui-panel layui-clear">
        当前位置：<span id="pos">网站管理 > 网站设置</span>
        <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="document.getElementById('iframe').contentWindow.location.reload(true);" style="float: right; margin-top: 5px;">
            <i class="layui-icon layui-icon-refresh"></i> 刷新本页
        </button>
    </div>
    <div class="iframe_wrapper">
        <iframe id="iframe" name="iframe" src="{:url('admin/index/main')}" frameborder="0" scrolling="auto" width="100%" height="100%"></iframe>
    </div>
</body>
</html>
<script src="/static/layui/layui.js"></script>
<script>
layui.use(function() {
    var $ = layui.jquery;

    $('.menu .layui-nav a[target="iframe"]').click(function() {
        $('.menu .layui-nav li').removeClass('layui-this');
        $(this).parents('li').addClass('layui-this');
        if ($(this).parent().is('dd')) {
            $('#pos').text($(this).parents('dl').prev().text() + ' > ' + $(this).text());
        } else {
            $('#pos').text($(this).text());
        }
    });

    $('#setPassword').click(function() {
        layer.prompt({title: '请输入新密码'}, function(value, index, elem){
            if (!(/^[\S]{6,18}$/.test(value))) {
                layer.alert('密码格式不正确（长度6-18位）', { icon: 2 });
            } else {
                var loadIndex = layer.load();
                $.post("{:url('admin/index/setpassword')}", {'password': value}, function(res) {
                    if (res.code > 0) {
                        layer.alert(res.msg, { icon: 2 });
                    } else {
                        layer.msg(res.msg, { time: 500 });
                    }
                    layer.close(loadIndex);
                });
            }
            layer.close(index);
        });
    });

    $('#logout').click(function() {
        var loadIndex = layer.load();
        $.get("{:url('admin/login/logout')}", function(){
            layer.msg('退出成功，正在跳转...', { time: 500 }, function() {
                window.location.href = "{:url('admin/login/index')}";
            });
            layer.close(loadIndex);
        });
    });
});
</script>